//% color="#FF9F06"
namespace arduinoGs01 {
/*
    //% block="GS01 Gesture/Face Detection Sensor Initialize I2C Mode Address 0x72"
    //% blockType="command"
    export function initI2CMode(parameter: any, block: any) {
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addSetup(`cs01.setFaceDetectThres`, `cs01.setFaceDetectThres(60);`);
        Generator.addSetup(`cs01.setGestureDetectThres`, `cs01.setGestureDetectThres(60);`);
        Generator.addSetup(`cs01.setDetectThres`, `cs01.setDetectThres(100);`);
    }
    //% block="AI视觉手势/人脸检测传感器 初始化 UART ESP32模式 地址0x72"
    //% blockType="command"
    export function initUART_ESP32Mode(parameter: any, block: any) {
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GestureFaceDetection.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GestureFaceDetection_UART`, `cs01(&Serial1, DEVICE_ID);`);
        Generator.addDefine(`DEVICE_ID`, `0x72`);
        Generator.addSetupTop(`Serial1.begin`, `Serial1.begin(9600,SERIAL_8N1, D2, D3);`);
     
    }
*/
    //% block="AI视觉手势/人脸检测传感器 初始化 UART模式 地址0x72"
    //% blockType="command"
    export function initUART_UNOMode(parameter: any, block: any) {
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GestureFaceDetection.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GestureFaceDetection_UART`, `cs01(&Serial, DEVICE_ID);`);
        Generator.addDefine(`DEVICE_ID`, `0x72`);
        Generator.addSetupTop(`Serial.begin`, `Serial.begin(9600,SERIAL_8N1);`);
     
    }
 //% block="设置 人脸[face]手势[hand]头肩[head]检测灵敏度"
    //% blockType="command"
       //% face.shadow="number"   face.defl="60"
    //% hand.shadow="number"   hand.defl="60"
    //% head.shadow="number"   head.defl="100"
    export function initUARTset(parameter: any, block: any) {
        let face = parameter.face.code;
        let hand = parameter.hand.code;
        let head = parameter.head.code;
        Generator.addSetupTop(`cs01.begin`, ``);

        Generator.addSetup(`cs01.setFaceDetectThres`, `cs01.setFaceDetectThres(${face});`);
        Generator.addSetup(`cs01.setGestureDetectThres`, `cs01.setGestureDetectThres(${hand});`);
        Generator.addSetup(`cs01.setDetectThres`, `cs01.setDetectThres(${head});`);
    }
    //% block="获取传感器[xinxi]"
    //% blockType="reporter"
   //% xinxi.shadow="dropdown" xinxi.options="xinxi"

    export function getGestureXinxi(parameter: any, block: any) { 
   let xinxi = parameter.xinxi.code

        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.${xinxi}`);
    }

    //% block="Get gesture type"
    //% blockType="reporter"
    export function getGestureType(parameter: any, block: any) { 
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.getGestureType()`);
    }
  //% block="获取手势得分"
    //% blockType="reporter"
    export function getGestureScore()(parameter: any, block: any) { 
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.getGestureScore()`);
    }
    //% block="Get the number of faces"
    //% blockType="reporter"
    export function getFaceNumber(parameter: any, block: any) { 
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.getFaceNumber()`);
    }
  //% block="获取人脸得分"
    //% blockType="reporter"
    export function getFaceScore()(parameter: any, block: any) { 
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.getFaceScore()`);
    }


    //% block="Get face X-coordinate"
    //% blockType="reporter"
    export function getFaceX(parameter: any, block: any) { 
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.getFaceLocationX()`);
    }

    //% block="Get face Y-coordinate"
    //% blockType="reporter"
    export function getFaceY(parameter: any, block: any) { 
        Generator.addInclude('DFRobot_GS01GestureSensor', '#include "DFRobot_GS01GestureSensor.h"');
        Generator.addObject(`DFRobot_GS01GestureSensor_cs01`, `DFRobot_GS01GestureSensor_I2C`, `cs01(0x72);`);
        Generator.addSetupTop(`cs01.begin`, `cs01.begin(&Wire);`);
        Generator.addCode(`cs01.getFaceLocationY()`);
    }
}
